﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;
using static System.Net.Mime.MediaTypeNames;
using System.Data.SqlClient;

namespace ConsoleApp6
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string connStr = "Data Source =test.db; Pooling = true; FailIfMissing = false";
            SQLiteConnection conn =new SQLiteConnection(connStr);
            try {
                conn.Open();
                Console.WriteLine("数据库连接成功！");
                using (SQLiteCommand cmd = conn.CreateCommand()) {
                    cmd.CommandText = "drop table t1";
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("删除数据库");
                    cmd.CommandText = "create table t1(id int,name varchar(30),score int)";
                    cmd.ExecuteNonQuery();
                    Console.WriteLine($"创建表t1成功=>{cmd.CommandText}");
                    string sname = "tt";
                    cmd.CommandText = $"insert into t1(id,name,score) values(1,'zhangsan',12)";
                    cmd.ExecuteNonQuery();
                    Console.WriteLine($"执行插入语句成功=>{cmd.CommandText}");
                    cmd.CommandText = $"update t1 set name='张飞'";
                    cmd.ExecuteNonQuery();
                    Console.WriteLine($"执行更新语句=>{cmd.CommandText}成功！");
                    cmd.CommandText = "select * from t1";
                    SQLiteDataReader dr=cmd.ExecuteReader();
                    Console.WriteLine($"查询数据=>{cmd.CommandText}");
                    while (dr.Read()) {
                        Console.WriteLine($"编号：{dr["id"]},姓名:{dr["name"]},成绩:{dr["score"]}");
                    }
                    dr.Close();
                }
                conn.Close();
                Console.WriteLine("数据库连接关闭");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
                }
            Console.ReadKey();
        }
    }
}
